package com.web.kdl.pojo.Vo.site;

import com.web.kdl.entity.flywheelDataAnalysis.FlywheelDataAnalysis;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DecimalFormat;
import java.util.List;

/**
 * @Author： shulibin
 * @Date： 2025/7/29 9:34
 * @Describe：
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SiteDetailVo {
    // 隶属飞轮
    private String deviceName;
    // 电机转速
    private String motorSpeed;

    private String soc;
    // 转子温度

    private String rotorTemperature;

    // 电机温度
    private String motorTemperature;

    // 充电计数
    private String chargeCount;

    // 放电计数
    private String dischargeCount;

    // 系统放电功率
    private String systemDischargePower;

    // 系统充电功率
    private String systemChargePower;

    public SiteDetailVo(List<FlywheelDataAnalysis> FlywheelDataAnalysisList) {
        this.setDeviceName(FlywheelDataAnalysisList.get(0).getSubSite()+"-"+FlywheelDataAnalysisList.get(0).getDataName().substring(0, 9));
        for (FlywheelDataAnalysis detail : FlywheelDataAnalysisList) {
            switch (detail.getDeviceName()) {
                case "转速":
                    this.setMotorSpeed(String.valueOf(detail.getDataValue()));
                    break;
                case "转子温度位移推算值":
                    // 保留小数点后两位
                    this.setRotorTemperature(keepTwoDecimalPlaces(detail.getDataValue()));
                    break;
                case "系统SOC":
                    this.setSoc(detail.getDataValue()+detail.getUnit());
                    break;
                case "电机温度1":
                    this.setMotorTemperature(keepTwoDecimalPlaces(detail.getDataValue())+detail.getUnit());
                    break;
                case "充电计数":
                    this.setChargeCount(String.valueOf(detail.getDataValue()));
                    break;
                case "放电计数":
                    this.setDischargeCount(String.valueOf(detail.getDataValue()));
                    break;
                case "系统可放电功率":
                    this.setSystemDischargePower(keepTwoDecimalPlaces(detail.getDataValue())+detail.getUnit());
                    break;
                // todo 冲->充
                case "系统可充电功率":
                    this.setSystemChargePower(keepTwoDecimalPlaces(detail.getDataValue())+detail.getUnit());
                    break;
            }
        }
    }
    // 保留两位小数点
    public String keepTwoDecimalPlaces(double value) {
        DecimalFormat df = new DecimalFormat("0.0");
        return df.format(value);
    }
}
